// 
// Decompiled by Procyon v0.5.36
// 

package com.cyberfend.cyfsecurity;

import android.os.*;
import com.cyberfend.cyfsecurity.b.*;
import android.hardware.*;
import android.util.*;
import java.util.*;

final class p implements java.util.Observer
{
    com.cyberfend.cyfsecurity.o a;
    boolean b;
    long c;
    long d;
    long e;
    private java.util.ArrayList<com.cyberfend.cyfsecurity.n> f;
    private java.util.ArrayList<com.cyberfend.cyfsecurity.p.a> g;
    private java.util.ArrayList<com.cyberfend.cyfsecurity.n> h;
    private float i;
    private float j;
    private float k;
    
    p() {
        this.a = null;
        this.b = false;
        this.c = 0L;
        this.d = 0L;
        this.e = 0L;
        this.f = new java.util.ArrayList<com.cyberfend.cyfsecurity.n>();
        this.g = new java.util.ArrayList<com.cyberfend.cyfsecurity.p.a>();
        this.h = new java.util.ArrayList<com.cyberfend.cyfsecurity.n>();
        this.i = 400.0f;
        this.j = 400.0f;
        this.k = 400.0f;
    }
    
    public final void a() throws java.lang.Exception {
        if (this.c >= 300L) {
            return;
        }
        final java.lang.Throwable[] array = new java.lang.Throwable[0];
        if (!this.a.a()) {
            com.cyberfend.cyfsecurity.b.a.c("OrientationManager", "Orientation listener registration failed", new java.lang.Throwable[0]);
            return;
        }
        this.b = true;
        this.a.addObserver(this);
    }
    
    public final void b() throws java.lang.Exception {
        final java.lang.Throwable[] array = new java.lang.Throwable[0];
        this.a.b();
        this.a.deleteObservers();
    }
    
    public final void c() {
        final java.lang.Throwable[] array = new java.lang.Throwable[0];
        this.d = android.os.SystemClock.uptimeMillis();
        this.f.clear();
        this.g.clear();
        this.h.clear();
        this.c = 0L;
    }
    
    public final com.cyberfend.cyfsecurity.b.b<java.lang.String, java.lang.Long, java.lang.Long> d() {
        try {
            final java.lang.Throwable[] array = new java.lang.Throwable[0];
            final java.util.ArrayList<java.lang.Object> list;
            (list = new java.util.ArrayList<java.lang.Object>(30)).addAll(this.f);
            list.addAll(this.h);
            final java.util.Iterator<com.cyberfend.cyfsecurity.p.a> iterator = this.g.iterator();
            while (iterator.hasNext()) {
                list.add(iterator.next().a);
            }
            java.util.Collections.<java.lang.Object>sort(list, (java.util.Comparator<? super java.lang.Object>)new com.cyberfend.cyfsecurity.p.b());
            final com.cyberfend.cyfsecurity.m m = new com.cyberfend.cyfsecurity.m();
            java.lang.String string = "";
            long n = 0L;
            long n2 = this.d;
            for (final com.cyberfend.cyfsecurity.n n3 : list) {
                final com.cyberfend.cyfsecurity.m i = m;
                final com.cyberfend.cyfsecurity.n n4 = n3;
                final long n5 = n2;
                final com.cyberfend.cyfsecurity.n n6 = n4;
                final com.cyberfend.cyfsecurity.m j = i;
                final float[] a = n6.a;
                final float[] b = n6.b;
                final float[] array2 = new float[9];
                android.util.Pair pair;
                if (!android.hardware.SensorManager.getRotationMatrix(array2, new float[9], a, b)) {
                    com.cyberfend.cyfsecurity.b.a.b("OrientationFormatter", "Failed to get rotation matrix", new java.lang.Throwable[0]);
                    pair = new android.util.Pair((java.lang.Object)"", (java.lang.Object)0L);
                }
                else {
                    final float[] array3 = new float[3];
                    android.hardware.SensorManager.getOrientation(array2, array3);
                    final float n7 = (float)java.lang.Math.toDegrees(array3[0]);
                    final float n8 = (float)java.lang.Math.toDegrees(array3[1]);
                    final float n9 = (float)java.lang.Math.toDegrees(array3[2]);
                    float n10;
                    if ((n10 = n7 * -1.0f) < 0.0f) {
                        n10 += 360.0f;
                    }
                    final java.lang.String format = j.a.format(n10);
                    final java.lang.String format2 = j.a.format(n8 * -1.0f);
                    final java.lang.String format3 = j.a.format(n9);
                    long n11;
                    if ((n11 = n6.c - n5) < 0L) {
                        n11 = 0L;
                    }
                    final java.lang.String string2 = n11 + "," + format + "," + format2 + "," + format3 + "," + n6.d + ";";
                    final long n12 = n11 + java.lang.Math.round((java.lang.Float.parseFloat(format) + java.lang.Float.parseFloat(format2) + java.lang.Float.parseFloat(format3)) * 100.0f);
                    new java.lang.StringBuilder("Orientation string ").append(string2).append(" time(ms): ").append(android.os.SystemClock.uptimeMillis() - n6.c);
                    final java.lang.Throwable[] array4 = new java.lang.Throwable[0];
                    pair = new android.util.Pair((java.lang.Object)string2, (java.lang.Object)n12);
                }
                final android.util.Pair pair2 = pair;
                string += (java.lang.String)pair2.first;
                n += (long)pair2.second;
                n2 = n3.c;
            }
            return new com.cyberfend.cyfsecurity.b.b<java.lang.String, java.lang.Long, java.lang.Long>(string, n, this.c);
        }
        catch (java.lang.Exception ex) {
            com.cyberfend.cyfsecurity.b.a.b("OrientationManager", "Exception in getting orientation events", ex);
            com.cyberfend.cyfsecurity.f.a(ex);
            return new com.cyberfend.cyfsecurity.b.b<java.lang.String, java.lang.Long, java.lang.Long>("", 0L, 0L);
        }
    }
    
    @java.lang.Override
    public final void update(final java.util.Observable observable, final java.lang.Object data) {
        try {
            final java.lang.Throwable[] array = new java.lang.Throwable[0];
            if (data == null) {
                return;
            }
            ++this.c;
            final com.cyberfend.cyfsecurity.n n = (com.cyberfend.cyfsecurity.n)data;
            if (this.f.size() < 10) {
                this.f.add(n);
            }
            else if ((n.c - this.e >= 1000L || n.d == 2) && this.h.size() < 10) {
                this.h.add(n);
                this.e = n.c;
                this.a(n);
            }
            else {
                final float a;
                if ((a = this.a(n)) != 0.0f) {
                    this.g.add(new com.cyberfend.cyfsecurity.p.a(n, a));
                    if (this.g.size() > 10) {
                        java.util.Collections.<com.cyberfend.cyfsecurity.p.a>sort(this.g);
                        this.g.remove(this.g.size() - 1);
                    }
                }
            }
            if (this.c >= 300L) {
                this.b();
            }
        }
        catch (java.lang.Exception ex) {
            com.cyberfend.cyfsecurity.b.a.b("OrientationManager", "Exception in processing orientation event", ex);
            com.cyberfend.cyfsecurity.f.a(ex);
        }
    }
    
    private float a(final com.cyberfend.cyfsecurity.n n) {
        final float[] a = n.a;
        final float[] b = n.b;
        final float[] array = new float[9];
        if (!android.hardware.SensorManager.getRotationMatrix(array, new float[9], a, b)) {
            com.cyberfend.cyfsecurity.b.a.b("OrientationManager", "Failed to get rotation matrix", new java.lang.Throwable[0]);
            return 0.0f;
        }
        final float[] array2 = new float[3];
        android.hardware.SensorManager.getOrientation(array, array2);
        final float n2 = (float)java.lang.Math.toDegrees(array2[0]);
        final float j = (float)java.lang.Math.toDegrees(array2[1]);
        final float k = (float)java.lang.Math.toDegrees(array2[2]);
        new java.lang.StringBuilder("Orientation: pitch: ").append(j).append(", roll: ").append(k).append(", yaw: ").append(n2);
        final java.lang.Throwable[] array3 = new java.lang.Throwable[0];
        float i;
        if ((i = n2 * -1.0f) < 0.0f) {
            i += 360.0f;
        }
        float max = 0.0f;
        if (this.i != 400.0f) {
            max = java.lang.Math.max(java.lang.Math.abs(this.i - i), java.lang.Math.max(java.lang.Math.abs(this.j - j), java.lang.Math.abs(this.k - k)));
        }
        this.i = i;
        this.j = j;
        this.k = k;
        final java.lang.Throwable[] array4 = new java.lang.Throwable[0];
        return max;
    }
    
    static final class a implements java.lang.Comparable<com.cyberfend.cyfsecurity.p.a>
    {
        com.cyberfend.cyfsecurity.n a;
        private float b;
        
        public a(final com.cyberfend.cyfsecurity.n a, final float b) {
            this.a = a;
            this.b = b;
        }
    }
    
    final class b implements java.util.Comparator<com.cyberfend.cyfsecurity.n>
    {
    }
}
